﻿/*
------------------------------
    Rodeo Game Engine
    Rodeo IO Module
    FileTGA.h - header file
    Copyright(c) Marcin Goryca
------------------------------
*/
#ifndef RODEO_IO_FILETGA_H_
#define RODEO_IO_FILETGA_H_

#ifndef RODEO_GLLIBS_H_
#include "..\gllibs.h"
#endif

#ifndef RODEO_CORE_CONSTANTS_H_
#include "core\constants.h"
#endif

#ifndef RODEO_CORE_ERROR_H_
#include "core\error.h"
#endif

#ifndef RODEO_RENDERER_COLORS_H_
#include "renderer\colors.h"
#endif

#ifndef RODEO_RENDERER_IMAGE_H_
#include "renderer\image.h"
#endif

#ifndef RODEO_RENDERER_FONT_H_
#include "renderer\font.h"
#endif

namespace rodeoio
{
class FileTGA : public rodeorenderer::Image
{
public:
    FileTGA()
        :filename_(""),
         colordepth_(0),
         imagesize_(0),
         hfile_(NULL),
         texture_id_(0)
    {}
    
    FileTGA(const char* new_filename)
        :filename_(new_filename),
         colordepth_(0),
         imagesize_(0),
         hfile_(NULL),
         texture_id_(0)
    {}
    
    virtual ~FileTGA()
    {}

    virtual bool open(const char* fileName);


    rodeocore::ui getColorDepth()const { return colordepth_; }
    rodeocore::ui getTextureId()const { return texture_id_; }

private :

    bool pickFile(const char* fileName);
    void swapRedBlue();
    void flipVertically();
    void convertRGBAToRGB();
    void convertRGBToRGBA();
    void draw(float x, float y);
    void release();

    virtual const char* getClassName()const{ return "FileTGA"; }

//==== MEMBERS ====//
private:
    const char* filename_;
    BYTE uheader_[12];
    BYTE cheader_[12];
    BYTE header_[6];
    rodeocore::ui colordepth_;

    rodeocore::ul imagesize_;
    HANDLE hfile_;
    rodeocore::ui texture_id_;
};
}    //end of rodeoio namespace
#endif	//RODEO_IO_TGAFILE_H_